Skip to content

[68697] Deselecting tree view items in single select does not work - #378

Merged
myabc merged 2 commits into
mainfrom
68697-deselecting-tree-view-items-in-single-select-does-not-work
Nov 2, 2025
Merged

[68697] Deselecting tree view items in single select does not work#378
myabc merged 2 commits into
mainfrom
68697-deselecting-tree-view-items-in-single-select-does-not-work

Conversation

@bsatarnejad

Copy link
Copy Markdown

What are you trying to accomplish?

Allow deselecting the selected item, while clicking on it.

Closes https://community.openproject.org/wp/68697

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.
  • Medium risk changes that are isolated, reduced in scope or could impact few users. The change will not impact library availability.
  • High risk changes are those that could impact customers and SLOs, low or no test coverage, low observability, or slow to rollback.

@changeset-bot

changeset-bot Bot commented Oct 31, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7f3e4ef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@openproject/primer-view-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables deselecting items in single-select tree views by clicking on the currently selected item. Previously, single-select tree views did not allow unchecking the checked item.

Key changes:

  • Modified handleSingleSelection method to support toggling selection state
  • Removed logic that prevented unchecking in single-select mode

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/components/primer/alpha/tree_view/tree_view.ts Updated handleSingleSelection to allow deselecting the currently selected item when clicked again
.changeset/sour-news-sip.md Added changeset documenting the new behavior allowing deselection in single-select mode
Comments suppressed due to low confidence (2)

app/components/primer/alpha/tree_view/tree_view.ts:337

  • The activeNodes getter uses document.querySelectorAll which queries the entire document rather than being scoped to this tree view component. When unchecking nodes in line 215, this will incorrectly uncheck all checked nodes across all tree views on the page, not just the current one. Change to this.querySelectorAll('[aria-checked=\"true\"]') to scope it to the current component.
  get activeNodes() {
    return document.querySelectorAll('[aria-checked="true"]')
  }

app/components/primer/alpha/tree_view/tree_view.ts:226

  • The treeViewNodeChecked event uses stale nodeInfo that was created at line 196 before the checked state was updated. This means the event will report incorrect checkedValue and previousCheckedValue. The nodeInfo should be regenerated after the checked state changes, or the event should be moved into the if/else branches with correctly computed values.
    this.dispatchEvent(
      new CustomEvent('treeViewNodeChecked', {
        bubbles: true,
        detail: [nodeInfo],
      }),
    )

Comment thread app/components/primer/alpha/tree_view/tree_view.ts Outdated
Comment thread app/components/primer/alpha/tree_view/tree_view.ts
Comment thread app/components/primer/alpha/tree_view/tree_view.ts

@myabc myabc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comment.

@myabc
myabc force-pushed the 68697-deselecting-tree-view-items-in-single-select-does-not-work branch from 9abda80 to 7f3e4ef Compare November 2, 2025 15:54
@myabc

myabc commented Nov 2, 2025

Copy link
Copy Markdown
Collaborator

@HDinger due to time constraints we skipped adding a test for this behaviour change. However, this is something we should still try to do (particularly before upstreaming)

@myabc
myabc merged commit 0f5ea12 into main Nov 2, 2025
13 of 15 checks passed
@openprojectci openprojectci mentioned this pull request Oct 31, 2025
// disallow unchecking checked item in single-select mode
if (!currentlyChecked) {
if (this.getNodeCheckedValue(node) === 'true') {
this.setNodeCheckedValue(node, 'false')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have preferred this.uncheckAtPath(path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants